fix(interpreter): populate BASH_SOURCE[0] for PATH-resolved scripts#1087
Merged
fix(interpreter): populate BASH_SOURCE[0] for PATH-resolved scripts#1087
Conversation
Pass the fully resolved candidate path instead of the bare command name to execute_script_content() when executing scripts found via PATH lookup. Closes #1085
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BASH_SOURCE[0]was empty because only the bare command name was passed toexecute_script_content()instead of the resolved pathtry_execute_script_via_path_search()to pass the fully resolvedcandidatepathWhat changed
In
try_execute_script_via_path_search(), the code already resolves the full path (candidate = PathBuf::from(dir).join(name)) but was discarding it when callingexecute_script_content(name, ...). Now passes&candidate.to_string_lossy()instead.Test plan
bash_source_set_via_path_lookup— verifies BASH_SOURCE[0] equals/scripts/test.shwhen run by name via PATHbash_source_guard_via_path_lookup— verifies source-guard pattern (BASH_SOURCE[0] == $0) works correctly via PATHcargo fmt --checkcleancargo clippy -- -D warningscleanCloses #1085